<?php require_once(dirname(__FILE__).'/inc/config.inc.php');IsModelPriv('account_log_list');
$starttimer = microtime(true);
$checkPagenum = isset($checkPagenum)? $checkPagenum  : $cfg_pagenum;
$action = isset($action) ? $action : 'list';
$keyword = isset($keyword) ? trim($keyword) : '';
$change_type = isset($change_type) ? trim($change_type) : 'all';

if($action == 'save')
{		
	$money = isset($money) ? $money : '';
	$points = isset($points) ? $points : '';
	$change_desc = isset($change_desc) ? $change_desc : '';
	
	
	
	if($points!='' || $money!=''){
	
		//权限属性
		$title='用户:'.$username.' 账户金额:'.$moneytype.$money.' 账户积分:'.$pointstype.$points;
		IsModelPriv('account_log','update','',$title);
		
		$r = $dosql->GetOne("SELECT `amount`,`integral` FROM `#@__member` WHERE `id`='$user_id'");
			
			$new_money=$r['amount']+($moneytype.$money);
			$money=$moneytype.$money;
		
			$new_points=$r['integral']+($pointstype.$points);
			$points=$pointstype.$points;
		$sql = "UPDATE `#@__member` SET `amount`='$new_money',`integral`='$new_points' WHERE `id`='$user_id'";
		if($dosql->ExecNoneQuery($sql))
		{		
			$change_time = GetMkTime(time());
			
			$dosql->ExecNoneQuery("INSERT INTO `#@__account_log` (`user_id`,`username`,`money`,`points`,`change_time`,`change_desc`,`change_type`) VALUES ('$user_id','$username','$money','$points','$change_time','$change_desc','2')");

			//header("location:account_log.php?id=$user_id&action=update");
			header("location:account_log.php");
			exit();
		}
	}
	else{
			Msg('未修改数据！','account_log.php?keyword='.$username);
			exit();
	}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,initial-scale=1.0,user-scalable=no" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<title>帐户变动</title>
<link href="templates/css/style.css" rel="stylesheet" type="text/css" />
<link href="templates/css/pagination.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" charset="utf-8" src="templates/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/Validform_v5.3.2_min.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/laymain.js"></script>
<script type="text/javascript" charset="utf-8" src="templates/js/common.js"></script>
<script type="text/javascript" src="templates/js/forms.func.js"></script>
<script src="../plugin/layer/layer.js"></script>


<script type="text/javascript">
   $(function () {
        //初始化表单验证
        $("#form").initValidform();
    });

</script>
</head>

<body class="mainbody">
<?php 
	if($action=='list')
{;?>
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i></i><span>返回上一页</span></a>
  <a href="home.php" class="home"><i></i><span>首页</span></a>
  <i class="arrow"></i>
  <span>会员日志</span>
  <i class="arrow"></i>
  <span>帐户变动明细</span>
  <a href="javascript:location.reload();" class="reload">刷新</a>
</div>
<!--/导航栏-->

<!--工具栏-->
<div id="floatHead" class="toolbar-wrap">

  <div class="toolbar">
    <div class="box-wrap">
      <a class="menu-btn"></a>
      <div class="l-list">
        <ul class="icon-list">
		 <?php if(IsModel('account_log','update',1)!=false and !empty($keyword)) echo'<li><a class="add" href="account_log.php?username='.$keyword.'&action=update"><i></i><span class="red">调节会员帐户</span></a></li>';?>
          <li><a class="all" href="javascript:;" onclick="checkAll(this);"><i></i><span>全选</span></a></li>
		 <?php if(IsModel($action,'del',1)) echo'<li><a href="javascript:SubUrlParam(\'account_log.php?action=delall\')" onclick="return ConfDelAll(0);" class="del"><i></i><span>删除</span></a></li>';?>
        </ul> 
      </div>
      <div class="s-list">
	  	  <form name="form3" id="form3" method="get" action="account_log.php" >
	  
		 <div class="single-select">
        <input name="keyword" type="text" id="keyword" class="keyword" value="<?php echo $keyword;?>"/>
		</div> <div class="single-select">
		    <input  class="btn-search" type="submit" value="搜索" style="cursor:pointer;"></div>
		</form>

      </div>
    </div>
  </div>
</div>
<!--/工具栏-->
<form method="post" action="" id="form">
<!--列表-->
<div class="table-container">

  <table width="100%" border="0" cellspacing="0" cellpadding="0" class="ltable">
    <tr>
		<th width="8%">选择</th>
		<th align="left" width="10%">用户名</th>
		<th align="left" width="10%">金额</th>
		<th align="left" width="10%">积分</th>
		<th align="left" >备注</th>
		<th align="left" width="10%">类型</th>
		<th width="16%">时间</th>
    </tr>
  <div id="listview"></div>
  	<?php
			$sql ="SELECT * FROM `#@__account_log` where id>0 ";

		if(!empty($keyword)) $sql .= " AND username LIKE '%$keyword%'";
		if(!empty($process_type)) 
		{
			if($process_type=='all')
			{
				$sql .='';
			}
			else{$sql .= " and `process_type` =  '$process_type'";}
			
		}
		
			if(!empty($change_type)) 
		{
			if($change_type=='all')
			{
				$sql .='';
			}
			else{$sql .= " and `change_type` = '$change_type'";}
			
		}
		$dopage->GetPage($sql,$checkPagenum);

		while($row = $dosql->GetArray())
		{	
			switch($row['change_type'])
				{
					case 0:
						$change_type = '充值';
						break;
					case 1:
						$change_type = '提现';
						break;
					case 2:
						$change_type = '系统';
						break;
					default:
						$change_type = '其它';
						break;
				}
				if($row['money']<0){
					$money='<span class="red">'.$row['money'].'</span>';
				}
				else{
					$money='<span class="green">'.$row['money'].'</span>';
				}
				if($row['points']<0){
					$points='<span class="red">'.$row['points'].'</span>';
				}
				else{
					$points='<span class="green">'.$row['points'].'</span>';
				}
		?>
		<tr align="center">
			<td ><span class="checkall" style="vertical-align:middle;"><input type="checkbox" name="checkid[]" value="<?php echo $row['id']; ?>" /></span></td>
			<td align="left"><?php echo $row['username'];?> </td>
			<td align="left"><?php echo $money;?> </td>
			<td align="left"><?php echo $points;?> </td>
			<td align="left"><?php echo $row['change_desc'];?> </td>
			<td align="left"><?php echo $change_type ;?> </td>
			<td > <?php echo GetDateTime($row['change_time']); ?></td>
		</tr>
		<?php
		}
		?>
		 <?php

//判断无记录样式
if($dosql->GetTotalRow() == 0)
{
	echo '<tr><td align="center" colspan="5">暂无记录</td></tr>';
}
?>
	 	<?php
			$sql ="SELECT * FROM `#@__account_log` where id>0 ";

		if(!empty($keyword)) $sql .= " AND username LIKE '%$keyword%'";
		if(!empty($process_type)) 
		{
			if($process_type=='all')
			{
				$sql .='';
			}
			else{$sql .= " and `process_type` =  '$process_type'";}
			
		}
		
		$dopage->GetPage($sql,$checkPagenum);

		while($row = $dosql->GetArray())
		{	
			switch($row['change_type'])
				{
					case 0:
						$row['change_type'] = '充值';
						break;
					case 1:
						$row['change_type'] = '提现';
						break;
					case 2:
						$row['change_type'] = '系统';
						break;
					default:
						$row['change_type'] = '其它';
						break;
				}
				if($row['money']<0){
					$row['money']='<span class="red">'.$row['money'].'</span>';
				}
				else{
					$row['money']='<span class="green">'.$row['money'].'</span>';
				}
				if($row['points']<0){
					$row['points']='<span class="red">'.$row['points'].'</span>';
				}
				else{
					$row['points']='<span class="green">'.$row['points'].'</span>';
				}
				$row['change_time']=GetDateTime($row['change_time']);
		?>
		
		
		<?php
		}
		
		?>
  </table>
</div>
<!--/列表-->
<!--内容底部-->
<div class="line20"></div>
<div class="pagelist">
 <div class="l-btns">
    <span>显示</span><input name="txtPageNum" type="text" value="<?php echo $checkPagenum;?>"  onblur="checkPagenum(this.id)"  onkeypress="if (WebForm_TextBoxKeyHandler(event) == false) return false;" id="txtPageNum" class="pagenum" onkeydown="return checkNumber(event);" /><span>条/页</span>
  </div>
  <?php echo $dopage->GetList($sql); ?>


  
  <div class="l-btns"><span>
<?php 
$stoptimer = microtime(true);
$timer = $stoptimer-$starttimer;
echo " $timer s";?></span>
</div>


</div>

<!--/内容底部-->
</form>

<?php 
};
	if($action=='update')
{
	$row = $dosql->GetOne("SELECT * FROM `#@__member` WHERE `username`='$username'");
	if(isset($row) && is_array($row))
	{
?>

<form name="form" id="form" method="post" action="account_log.php?action=save" >
<!--导航栏-->
<div class="location">
  <a href="javascript:history.back(-1);" class="back"><i></i><span>返回列表页</span></a>
  <a href="home.php" class="home"><i></i><span>首页</span></a>
  <i class="arrow"></i>
  <a href="member.php"><span>调节会员帐户</span>
  <a href="javascript:location.reload();" class="reload">刷新</a> 
</div>
<div class="line10"></div>
<!--/导航栏-->
<!--内容-->
<div id="floatHead" class="content-tab-wrap">
  <div class="content-tab">
    <div class="content-tab-ul-wrap">
      <ul>
        <li><a class="selected" href="javascript:;">调节会员帐户</a></li>
      </ul>
    </div>
  </div>
</div>

<div class="tab-content" style="overflow: visible" >
	<dl>
	<dt>当前会员:</dt>
	<dd><?php echo  $row['username'];?></dd> 
	</dl>
	<dl>
		<dt>变动原因:</dt>
		<dd>
		 <textarea name="change_desc" rows="2" cols="20" id="change_desc" class="input"></textarea>
		</dd>
	</dl>		
	  <dl>
		<dt>账户金额:</dt>
		<dd><div class="rule-single-select" >
       	<select name="moneytype" id="moneytype" >
		<option value="+">增加</option>
		<option value="-">减少</option>
		</select>
      </div>
		<input name="money" type="text" id="money"  class="input" />
			<span class="Validform_checktip">当前金额: <?php echo  $row['amount'];?></span>
		</dd>
	  </dl> 
	 <dl>
		<dt>账户积分:</dt>
		<dd><div class="rule-single-select" >
       	<select name="pointstype" id="pointstype" >
		<option value="+">增加</option>
		<option value="-">减少</option>
		</select>
      </div>
		<input name="points" type="text" id="points"  class="input" />
		<span class="Validform_checktip">当前积分: <?php echo  $row['integral'];?></span>
		</dd>
	  </dl> 

</div>
<!--/内容-->

<!--工具栏-->
<div class="page-footer">
  <div class="btn-wrap">
  <input type="submit" name="btnSubmit" value="提交保存" id="btnSubmit" class="btn" />
    <input name="btnReturn" type="button" value="返回上一页" class="btn yellow" onclick="javascript:history.back(-1);" />
	<input type="hidden" name="action" id="action" value="save" />
	<input type="hidden" name="user_id" id="user_id" value="<?php echo $row['id'];?>" />
	<input type="hidden" name="username" id="username" value="<?php echo $row['username'];?>" />
  </div>
</div>

<!--/工具栏-->

</form>
<?php }
else{
Error('无此会员','-1','time: 1000');
exit();
}
};

//删除多条记录
if($action == 'delall')
{

	foreach($checkid as $k => $v)
		{
			$r = $dosql->GetOne("SELECT * FROM `#@__account_log` WHERE `id`=$v");
			IsModelPriv('account_log','del','','会员：'.$r['username'].'金钱：'.$r['money'].'积分：'.$r['points'].'备注：'.$r['change_desc']);
			$dosql->ExecNoneQuery("DELETE FROM `#@__account_log` WHERE id=$v");
		}
	header("location:account_log.php");
	exit();
}


?>

</body>
</html>